/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.xtd.model.inventory;

import com.xtd.model.employment.Employee;
import com.xtd.model.settlement.Form;
import com.xtd.util.FormTypeEnum;
import java.util.Date;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;

import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.annotations.IndexColumn;

/**
 *
 * @author Lu Yuanbin
 */
@Entity
@Table(name = "purchase_form")
@NamedQueries({
    @NamedQuery(name = "PurchaseForm.findAll", query = "SELECT p FROM PurchaseForm p")})
public class PurchaseForm extends Form {

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.DELETE, org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
    @JoinColumn(name = "form")
    @IndexColumn(name = "purchase_record_position", base = 0)
    private List<PurchaseRecord> purchaseRecordCollection;

    public PurchaseForm() {
    }

    public PurchaseForm(String formNumber,Employee createdBy) {
        super(formNumber,FormTypeEnum.采购);
        this.setCreatedBy(createdBy);
        this.setCreatedTime(new Date());

    }

    public boolean isNew() {
        if (getId() == null) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (getId() != null ? getId().hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the getId() fields are not set
        if (!(object instanceof PurchaseForm)) {
            return false;
        }
        PurchaseForm other = (PurchaseForm) object;
        if ((this.getId() == null && other.getId() != null) || (this.getId() != null && !this.getId().equals(other.getId()))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.xtd.model.inventory.PurchaseForm[getId()=" + getId() + "]";
    }

    /**
     * @return the purchaseRecordCollection
     */
    public List<PurchaseRecord> getPurchaseRecordCollection() {
        return purchaseRecordCollection;
    }

    /**
     * @param purchaseRecordCollection the purchaseRecordCollection to set
     */
    public void setPurchaseRecordCollection(List<PurchaseRecord> purchaseRecordCollection) {
        this.purchaseRecordCollection = purchaseRecordCollection;
    }
}
